package com.gzsxy.esjy.configuration;


import com.gzsxy.esjy.configuration.properties.ServerProperties;
import com.gzsxy.esjy.decoder.impl.HttpContentDecoder;
import com.gzsxy.esjy.decoder.impl.HttpRequestDecoder;
import com.gzsxy.esjy.filter.Ifilter;
import com.gzsxy.esjy.handler.HttpHandler;
import com.gzsxy.esjy.mapping.MappingInit;
import com.gzsxy.esjy.thread.ExcuteService;
import com.gzsxy.esjy.thread.NettyServicePool;

import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;

/**
 * netty处理工厂
 * @author zhangxiaolong
 * @date 2022/7/6 9:36
 */
public class NettyHandlerFactory {

	/**
	 * 线程池
	 */
	@Autowired
	private NettyServicePool pool ;
	
	@Autowired
	private ExcuteService excuteService;
	
	@Autowired
	private ServerProperties properties;
	@Autowired
	private MappingInit mappingInit;
	
	@Autowired(required=false)
	private Ifilter ifilter ;
	
	@Autowired(required=false)
	private NettyServerConfig nettyServerConfig;
	
//	@PostConstruct
//	private void init() {
//
//	}
	
	/**
	 * httphandler
	 * @return
	 */
	private HttpHandler httpHandler() {
		return new HttpHandler(pool,excuteService,true);
	}
	
	/**
	 * request 解码
	 * @return
	 */
	public HttpRequestDecoder httpRequestDecoder() {
		return new HttpRequestDecoder(mappingInit, ifilter,nettyServerConfig,httpHandler(), properties) ;
	}
	/**
	 * request 解码
	 * @return
	 */
	public HttpContentDecoder httpContentDecoder() {
		return new HttpContentDecoder() ;
	}
}
